Hello and welcome to the part two of adding javascript to our prayer.
The next thing I want to do is create a function that will allow the mall to peek is head out of the
mall.
He'll survive.
Click on this start.
Here you see the head popping up so that's what we're trying to achieve something to create the function
that will achieve that.
I have added the function called Peep So this is the function down allow the more to keep its head out
of the mole hill.
So I've created some constants here constant time I called it time and I've set it to cause to run some
time and a past to a time of this is a millisecond This is 200 milliseconds.
And this is one this is 10 seconds.
Okay.
So we've got the random time here which we are using from the random time function.
So we are calling the random time function here passing it values in many seconds.
Okay here we've got variable here constant again chord hall and we are setting that to cause the random
function how inside that is taking in the perimeters for the calls.
And here we are in a class there's a csx class which will be called this physically here will trigger
the CSA.
So if you look inside this here's a how to get to class here quad up.
So that's what that is referring to.
So it's adding that on to that success.
And we're set in a time out because we don't want it to pick his head out forever.
So this time out we use our function here.
So grunt's is picked to serve.
The time has elapsed.
It will remove this csx It will remove the class and if it tells you here that this condition statement
if the time is up it will call the pip function which is this function here or so for the time.
So to begin with the time is set to be false.
You can see here we've got the let's statements end time up is false.
So to begin it would be start to be false and then later it it'll be.
Once the time elapses that condition is no longer true.
Next I want to do is create the function that will start the game.
So again I priest t could hear.
So this is the function that will be used to start the game.
So on line 6 AM added a letter statement for the score and the default score which will be zero.
So if I go back in to my start game function this is the function that will start the game.
So when you click on the button it will trigger this function and when the function runs a tool set
the scoreboard to zero and the initial time warp is going to be false so you can see here we'll call
the time OP statement is false.
Initially it will be false and the score also will be set to zero and then to start the game by calling
this peep function where the mall would -- outside of this hall.
Each of the holes randomly switch to a randomly pick is said out of Iran them all.
However when the time lapses is all it has 10 seconds to do that.
So when that 10 seconds elapse is this set time out is called and the Time War is no longer of force
this time of value becomes true when that 10 seconds has elapsed final function.
I want to add is some implementation of scoring here.
So right up here I have got on I've got the initial score here set to zero.
So this is a function I've just had it here.
I've created a function called it whack t the e is basically the event.
What this will do exactly is that when the mall picks his head out of the molehill.
The goal here is to try and click on it or whack it with your mouse.
And if you are able to do that it disk it will give it a point which this is it all changed the value
of the score variable plus blows me.
It would increase the value.
1.
So for every successful whack of the mall when he picks his head out you get one point.
This here will go.
If he was referring to this event is trusted to a return.
This is this is trusted here basically is an event property that returns the bullion value indicating
where the event is.
Did not so if someone is trying to cheat by not actually go into the right process thus Ward this this
or it will return.
Okay so this bullion is.
Is it true or false value.
So if these give the value of that is trust to property it's a bulimba I leave it to indicate whether
the event is trusted or not.
So each time you successfully whack the mall when he picks his head out this score count will increase
to 1 using this plus plus And then what happens.
This keyword this refers to the current instance the actual parent node.
It will then remove this class.
Okay so this here is reference to inside this vss.
Alright so we to remove this.
Classes are the same says clout who did it would then remove it.
Once you've successfully whacked it and then this core board content will set to the current score so
each time you successfully whack it.
This is what will happen and then the score board will change like 50.
Basically what we're seeing here for each of the mall that you whack.
We add in an event who I missed out.
Okay I missed this close in parenthesis here.
Right so here for each of the more we are attached in an event list now so this add listener basically
allows you to listen out for an event and event is listening not for is the click event so each time
we're able to click to work more by clicking on it with the mouse to trigger this function called Whack.
That's basically what that is is calling it a reference this function when we're able to successfully
click on the Mall talk whack it is in our using the click of the mouse.
So that's basically a project completed.
With this he says obviously you can improve on this projet.
There's a lot you can do.
You can add a process that will retain the previous score or keep a score higher score and still you
can also there's a lot you can do to improve on the game.
I'm going to save that and then we can run it and test the whole game.
So I'm going to run by clicking on the index FAQ here.
And just click on the start button.
So the goal here is to try and whack the mall as he puts his head out of the hole.
So start so I click on start to see go on points.
I've got 10 seconds to do this.
See Okay I'm not doing too bad here.
See I got three points only 10 seconds after lap so if I start again and then the process begins again
so that's basically the game complete at a it.
Thanks for watching and bye for now.